package com.syezon.wifikey.safe.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.syezon.wifikey.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


public class CheckItemAdapter extends RecyclerView.Adapter<CheckItemAdapter.EnhanceItemViewHolder> {

    private Context mContext;
    private List<String> mData = new ArrayList<>();

    public CheckItemAdapter(Context context) {
        this.mContext = context;
    }

    public void setData(List<String> data) {
        if (data != null) {
            mData.clear();
            mData.addAll(data);
            notifyDataSetChanged();
        }
    }

    public void addData(String enhanceItemInfo) {
        if (enhanceItemInfo != null) {
            mData.add(enhanceItemInfo);
            notifyItemInserted(mData.size() - 1);
        }
    }


    @NonNull
    @Override
    public EnhanceItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new EnhanceItemViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_check , parent ,false));
    }

    @Override
    public void onBindViewHolder(@NonNull EnhanceItemViewHolder holder, int position) {
        String title = mData.get(position);
        holder.tvTitle.setText(title);
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public static class EnhanceItemViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_title)
        TextView tvTitle;

        public EnhanceItemViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
